/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package african11;

import java.util.Arrays;
import java.io.IOException;
import static chanlib.Chan_IO.*;

/**
 * @author robit
 */
public class ClosingTheLoop{
    /*
      All neccesary to be defined
      including:
      variable, inner class
    */
    // static int A;
    // static void B();
    // static class C

    /*
       One calculation fits all of the cases.
    */
    static void preReckon(){
        return;
    }

    /*
      calculate the answer
    */
    private static void reckon(int line) {
        int S=Int();
        int Rc=0,Bc=0;
        int RList[]=new int[S],BList[]=new int[S];
        for(int i=0;i<S;i++){
            String seg=String();
            int len=seg.length();
            if(seg.endsWith("R")){
                RList[Rc++]=Integer.parseInt(seg.substring(0,len-1));
            }
            else if(seg.endsWith("B")){
                BList[Bc++]=Integer.parseInt(seg.substring(0,len-1));
            }
        }
        int n=Math.min(Rc, Bc);
        Arrays.sort(RList);Arrays.sort(BList);
        int sum=0;
        for(int i=1;i<=n;i++){
            sum+=RList[S-i]+BList[S-i]-2;
        }

        String ans =""+sum;
        //for(int i=0;i<)
        String output=String.format("Case #%d: %s",line,ans);
        writeln(output, OUTFILE);
        //writeln(String.format("%s\n%s", track , ans),ANALFILE);
        //println(output);
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        /*
           Pre-computing for all cases
        */

        // Just in case!
        //preReckon();
        //while((char)read()!='P');

        /*
          Input-output
        */
        boolean test=false;
        boolean small=false;
        String prob="A";
        String filename;
        if(test) filename="test";
        else{
            if(small) filename=prob+"-small-practice";
            else filename=prob+"-large-practice";
        }
        try {
            /*
               Init IO,plus determination of input line number
             */
            int lineNums = initFileIO(filename);
            for (int i = 1; i <= lineNums; i++) {
                reckon(i);
            }
        } finally {
            endIO();
        }
    }

}
